package main

import (
	"fmt"
	"strings"
	"time"

)

func chunk(value string) string {
	if value == "" {
		return "-"
	}
	return value
}

// Stdout struct implements proxy.Logger
type Stdout struct {
}

// Log prints a standard log string to the system.
func (s Stdout) Log(pr *ProxiedRequest) error {

	line := []string{
		chunk(pr.Request.RemoteAddr),
		chunk(""),
		chunk(""),
		chunk("[" + time.Now().Format("02/Jan/2006:15:04:05 -0700") + "]"),
		chunk("\"" + fmt.Sprintf("%s %s %s", pr.Request.Method, pr.Request.URL, pr.Request.Proto) + "\""),
		chunk(fmt.Sprintf("%d", pr.Response.StatusCode)),
		chunk(fmt.Sprintf("%d", pr.Response.ContentLength)),
	}

	fmt.Println(strings.Join(line, " "))

	return nil
}
